package demo.game.chess.common;

public class PieceKnight extends AbstractChessPiece {

	private static final int[] HORIZONTAL_DIRECTION = { 2, 2, -2, -2, 1, -1, 1,
			-1 };

	private static final int[] VERTICAL_DIRECTION = { 1, -1, 1, -1, 2, 2, -2,
			-2 };

	public PieceKnight(final ChessCell initialPosition) {
		super(initialPosition);
	}

	@Override
	protected ChessMove createPieceSpecificMove(final ChessBoard board,
			final ChessCell origin, final ChessCell target) {

		for (int i = 0; i < HORIZONTAL_DIRECTION.length; i++) {
			if (target.getRow() == origin.getRow() + VERTICAL_DIRECTION[i]
					&& target.getColumn() == origin.getColumn()
							+ HORIZONTAL_DIRECTION[i]) {
				return new ChessMove(origin, target);
			}
		}
		return null;
	}

	@Override
	public EnumChessPiece getType() {
		return EnumChessPiece.knight;
	}
}
